import requests

def crawl_lottery_info():
    url = "https://www.lottery.gov.cn/tz_kj.json"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
    }
    response = requests.get(url, timeout=10, headers=headers)
    response.raise_for_status()  # 抛出HTTP错误状态码
    data = response.json()[0]
    dlt_data = data['dlt']
    dlt_code = dlt_data['term']
    dlt_all_code = dlt_data['numberCode']
    dlt_front_info = dlt_all_code[:5]
    dlt_back_info=  dlt_all_code[-2:] if len(dlt_all_code) >= 2 else []
    print(f"大乐透->期号{dlt_code} 前5：{dlt_front_info} 后2：{dlt_back_info}")
    pl3_data = data['pls']
    pl3_code = pl3_data['term']
    pl3_info = pl3_data['numberCode']
    print(f"排列3->期号{pl3_code} 号码：{pl3_info}")
    pl5_data = data['plw']
    pl5_code = pl5_data['term']
    pl5_info = pl5_data['numberCode']
    print(f"排列5->期号{pl5_code} 号码：{pl5_info}")
    return {
        "dlt_code": dlt_code,
        "dlt_front_info": dlt_front_info,
        "dlt_back_info": dlt_back_info,
        "pl3_code": pl3_code,
        "pl3_info": pl3_info,
        "pl5_code": pl5_code,
        "pl5_info": pl5_info,
    }